package services;

import java.util.List;

import com.xyz.Film;
import dao.FilmsDao;
import jdbc.ConnectionManager;

public class FilmsService {
	private FilmsService(){}
	
	private static final FilmsService instance=new FilmsService();
	public static FilmsService getInstance(){
		return FilmsService.instance;
	}
	
	ConnectionManager connectionManager=ConnectionManager.getInstance();
	FilmsDao filmsDao=new FilmsDao();
	
	public List<Film> getFilmsByGenre(String genre){
		try{
			List<Film> films=filmsDao.getByGenre(genre);
			connectionManager.commitTransaction();
			return films;
		}
		catch(Exception e){
			connectionManager.rollbackTransaction();
			throw e;
		}
	}
	
	public List<Film> getFilmsByYear(int min, int max){
		try{
			List<Film> films=filmsDao.getByYear(min, max);
			connectionManager.commitTransaction();
			return films;
		}
		catch(Exception e){
			connectionManager.rollbackTransaction();
			throw e;
		}
	}
	
	public List<Film> getAllFilms(){
		try{
			List<Film> films=filmsDao.getAll();
			connectionManager.commitTransaction();
			return films;
		}
		catch(Exception e){
			connectionManager.rollbackTransaction();
			throw e;
		}
	}

	
}
